package org.spring.core.io;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * 文件系统资源处理类
 *
 * @author 李坤
 * @date 2022/4/17 13:59
 */
public class FileSystemResource implements Resource {

    /**
     * 文件路径
     */
    private final Path path;

    public FileSystemResource(Path path) {
        this.path = path;
    }

    public FileSystemResource(File file) {
        this(file.toPath());
    }

    public FileSystemResource(String filePath) {
        this(Paths.get(filePath));
    }

    @Override
    public InputStream getInputStream() throws IOException {
        return Files.newInputStream(this.path);
    }
}
